layui.use(['element', 'layer', 'upload', 'form'], function() {
	var upload = layui.upload
	layer = parent.layer === undefined ? layui.layer : top.layer,
		form = layui.form,
		element = layui.element,
		$ = layui.jquery;
	form.render();
	
	var id = sessionStorage.getItem("userid");
	
	layer.msg(id);
    
	$.ajax({
    	type:"get",
    	url:"http://127.0.0.1/yh/selectOneUsergetgoodsByUserId",
    	data:{"userid":id},
    	dataType:"json",
    	success:function(data){
    		form.val("updateUser", { 
    			   "id": id
    			  ,"userName": data.data[0].userName 
    			  /*,"pwd": data.data[0].pwd*/
    			  ,"name": data.data[0].name
    			  ,"email": data.data[0].email
    			  ,"u_type": data.data[0].u_type
    			  ,"sex": data.data[0].sex
    			  ,"phone": data.data[0].phone
    			  ,"address": data.data[0].address
    			  ,"birthday": data.data[0].birthday
    			  ,"salt": data.data[0].salt
    			  ,"balance": data.data[0].balance
     			});
     			
    	}
    })
	

	form.on("submit(updateUserBut)", function(data) {

		var pwd=hex_md5($("#pwd").val());
        $("#pwd").val(pwd);
		//弹出loading
		var index = top.layer.msg('数据提交中，请稍候', {
			icon: 16,
			time: false,
			shade: 0.8
		});

		$.ajax({
			type: "post",
			url: "http://127.0.0.1/yh/updateUserAllNews",
			data: $("#updateUser").serialize(),
			dataType: "json",
			async: false,
			success: function(data) {
				if(data.code == 0) {
					layer.msg(data.msg, {
 							icon: 1,
  							time: 2000 //2秒关闭（如果不配置，默认是3秒）
							}, function(){
  								location.href="../user.html";
							}); 					
				}
			}
		})
		return false;
	})

})